package top.songxs.gmall.user.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.songxs.gmall.common.result.Result;
import top.songxs.gmall.user.dto.UserLoginDTO;
import top.songxs.gmall.user.service.UserInfoService;
import top.songxs.gmall.user.vo.UserLoginSuccessVo;

@RestController
@RequestMapping("/api/user/passport")
public class UserController {

    @Autowired
    private UserInfoService userInfoService;

    @PostMapping("login")
    public Result<UserLoginSuccessVo> login(@RequestBody UserLoginDTO userLoginDTO){
        UserLoginSuccessVo userLoginSuccessVo = userInfoService.login(userLoginDTO);

        return Result.ok(userLoginSuccessVo);
    }


    @GetMapping("/logout")
    public Result logout(@RequestHeader("token") String token){
        userInfoService.logout(token);
        return Result.ok();
    }

    @GetMapping("/logoutBak")
    public Result logoutBak( @RequestParam("token") String token){
        userInfoService.logout(token);
        return Result.ok();
    }
}
